package com.canbot.u05.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.canbot.u05.R;
import com.canbot.u05.activity.customvoice.CustomDialogMainActivity;
import com.canbot.u05.api.U05RobotManger;
import com.canbot.u05.socket.IpMsgConst;
import com.canbot.u05.socket.MsgSendUtils;
import com.canbot.u05.socket.MsgType;
import com.canbot.u05.utils.OkHttpUtils;
import com.canbot.u05.utils.PathConst;
import com.canbot.u05.utils.ToastTools;
import com.canbot.u05.widget.LoadingDialogUtils;

import java.util.HashMap;

/**
 * 手持pad  定制中心
 */
public class BasicServerActivity extends BaseActivityNoTitle {

        private BasicServerActivity mContext;

        private ToastTools toastTools;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.act_basic_server);
                toastTools = ToastTools.newInstance(this);
                mContext = this;
        }

        @Override
        protected void onResume() {
                super.onResume();
                U05RobotManger.getInstance().playSound(PathConst.PAD_MODE_DIR + "jcfw 01.wav");
        }

        protected void startotherActivity(Context context, Class<?> cls) {
                Intent intent = new Intent(context, cls);
                startActivity(intent);
        }

        public void back(View view) {
                //停止播放音频
                MsgSendUtils.sendStringMsg(MsgType.STOP_SOUND, "stop_sound");
                finish();

        }



        private Dialog dialogLoading;

        public void mapedit(View view) {
                initMapSocket();
                dialogLoading = LoadingDialogUtils.createLoadingDialog(this, getString(R.string.loading));
        }

        private void initMapSocket() {
                String url = IpMsgConst.HTTP_URL_CHEST + "guideMapAction";
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("type", 10 + "");
                OkHttpUtils.upLoadFile(url, hashMap, new OkHttpUtils.OkHttpCallBack() {
                        @Override
                        public void onSuccess(String result) {
                                LoadingDialogUtils.closeDialog(dialogLoading);
                                Log.e("TTS2Voice", result);
                                Intent intent = BasicServerActivity.this.getPackageManager()
                                        .getLaunchIntentForPackage("com.canbot.slamtec.maptools.u05");
                                if (intent != null) {
                                        startActivity(intent);
                                }
                                else {
                                        toastTools.showText(getString(R.string.not_available));
                                }
                        }

                        @Override
                        public void onFailure() {
                                LoadingDialogUtils.closeDialog(dialogLoading);
                                toastTools.showText(getString(R.string.network_error));
                        }
                });
        }

        /**
         * 跳转到人脸识别界面
         *
         * @param view
         */
        public void facerecognition(View view) {
                Intent intent = new Intent();
                intent.setClassName("com.unisrobot.faceregcognize", "com.unisrobot.faceregcognize.activity.FaceRegRegisterActivity");
                if (intent != null) {
                        startActivity(intent);
                }
        }

        public void advisory(View view) {
                startotherActivity(mContext, CustomDialogMainActivity.class);
        }



}
